
package uk.ac.glasgow.demosocs.impl.ui;

import java.util.Date;

import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.ElectionImpl;

@MinimumArguments(0)
@CommandDescription("Stop the currently selected election.")
public class StopElectionCommand extends SystemCommand<VotingSystem> {

	public StopElectionCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments) throws SystemCommandException {
		String guid = facade.getCurrentUserGUID();
		if (guid == null)
			throw new SystemCommandException("No current user set.");
		
		
		Election election = facade.getCurrentElection();
		ElectionImpl e = ((ElectionImpl) election);
		
		if (election == null)
			throw new SystemCommandException("No current election set.");
		
		Date current = new Date();
		facade.editElection(e.getOpenNominations(), e.getStart(), current, e.getElectorateID());
		return "Attempted command stop election " + e.getEID();
		
	}

}
